/**
 * Created by huotaol on 2017/5/9.
 */
import React, {Component} from "react";
import {Text, TouchableOpacity, View} from "react-native";
import CustomStyle from "../../../common/style/CustomStyle";
import {connect} from "react-redux";
import MineItem from "../../components/MineItem";
import {Actions} from "react-native-router-flux";
import Util from "../../main/Util";
import Toast from "react-native-root-toast";
import * as MineAction from "../../redux/action/Mine";
import ModuleCommonHeader from "../../main/module/ModuleCommonHeader";

class Setting extends Component {
    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {};
        this._renderQuit = this._renderQuit.bind(this);
    }

    render() {
        return (
            <View style={{flex: 1, backgroundColor: '#FFFCEE',}}>
                <ModuleCommonHeader title={'设置'}/>
                {HANDLE_LIST.map(item => {
                    return <MineItem title={item.title} style={{backgroundColor: 'white',}}/>
                })}
                {this._renderQuit()}
            </View>
        );
    }

    _renderQuit() {
        if (this.props.userData.info) {
            return <TouchableOpacity
                style={[, {
                    alignItems: 'center',
                    justifyContent: 'center',
                    height: CustomStyle.getActualSizeInVertical(100),
                    backgroundColor: 'white',
                    marginTop: CustomStyle.getActualSizeInVertical(20),
                }]}
                onPress={() => {
                    Util.storage.clearMapForKey('users');
                    this.props.updateUser({});
                    Toast.show("已退出登录", {duration: Toast.durations.SHORT, position: Toast.positions.CENTER});
                    Actions.pop();
                }}
            >
                <Text
                    style={[CustomStyle.baseText, {
                        fontSize: CustomStyle.getActualFontSize(30),
                        color: '#bc7a44',
                        marginLeft: CustomStyle.getActualSizeInHorizontal(20),
                    }]}>退出当前账号</Text>
            </TouchableOpacity>;
        }
    }
}

const HANDLE_LIST = [
    {title: '意见反馈'},
    {title: '常见问题'},
    // {title: '版本更新'},
];

const mapStateToProps = (state) => {
    const {userData} = state;
    return {
        userData: userData,
    };
};

const mapDispatchToProps = (dispatch) => {
    return {
        updateUser: param => dispatch(MineAction.userData(param)),
    };
};


export default connect(mapStateToProps, mapDispatchToProps)(Setting);